// pages/add/add.js
const task = require('../../service/task/task');//app.js
const moment = require('../../utils/moment.min');//app.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: moment().format('YYYY-MM-DD'),
    days: 0,
    money:0,
    detail:'',
    today: new Date(),
    showDialog: false,
    pay: 1,
    payArr: ['微信支付']
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  bindDateChange: function ({ currentTarget, detail }) {
    this.setData({
      date: detail.value
    })
  },
  bindKeyInput1:function(e){
    let days = e.detail.value.trim();
    this.data.days = days;
  },
  bindKeyInput2: function (e) {
    let money = e.detail.value.trim();
    this.data.money = money;
  },
  oninput:function(e){
    let detail = e.detail.value.trim();
    this.data.detail = detail;
  },

  toggleDialog() {
    this.setData({
      showDialog: !this.data.showDialog
    });
  },

  bindPayChange ({ detail }) {
    this.setData({
      pay: detail.value
    })
  },

  commintForm:function(){
    let desc = this.data.detail;
    let amount = this.data.money;
    let repeat_times = this.data.days;
    let start_time = this.data.date;
    const query = wx.createSelectorQuery().in(this)

    task.add(amount, desc, repeat_times, start_time).then(res => {
      // console.log(res);
      if (res.data.code === 1000) {
        // query.select('.zan-field__input').tap();
        wx.navigateTo({
          url: '../detail/detail?id=' + res.data.data.id
        });
      } else {
        console.log(res.data.msg);
      }
    }).catch(res => {
      console.log(res);
    })
  }

})